#ifndef _TINY_SYSTEM_
#define _TINY_SYSTEM_
#include "core/include/types.h"

#include "app/cv/include/aksImage.h"
#include "core/include/list.h"

/* ------------ rev2 tiny system address map ------------ */
/* ------ Header : 0x00 - 0x07 ------ */
#define TINY_HEADER_LEN			0x00
#define TINY_MAGIC_NUM			0x01
#define TINY_REVISION			0x02
#define TINY_TYPE				0x03
#define TINY_SLAVE_ADR			0x04

/* ------ GPIO0 block : 0x08 - 0x0F ------ */
#define TINY_GPIO0_CAPABILITY	0x08
#define TINY_GPIO0_SETTING		0x09

/* ------ GPIO0 block : 0x10 - 0x17 ------ */
#define TINY_GPIO1_CAPABILITY	0x10
#define TINY_GPIO1_SETTING		0x11

/* ------ GPIO0 block : 0x18 - 0x1F ------ */
#define TINY_GPIO2_CAPABILITY	0x18
#define TINY_GPIO2_SETTING		0x19


/* ------------------ rev2 ------------------ */
/* GPIO0 : PORTB[1] GPIO                      */
/* GPIO1 : PORTB[4] GPIO/PWM                  */
/* GPIO2 : PORTB[3] GPIO/ADC                  */
/*--------------------------------------------*/
typedef union st_GPIO
{
    unsigned char byte;
    struct
    {
    	unsigned char MUX    : 2;
    	unsigned char DIR    : 1;
    	unsigned char OUTPUT : 1;
    	unsigned char RSVD   : 4;
    } bit;
} TINY_GPIO;

#define TINY_MUX_GPIO    0x00
#define TINY_MUX_PWM     0x01
#define TINY_MUX_ADC     0x02

#define TINY_MUX_CAP_GPIO    (0x01 << MUX_GPIO)
#define TINY_MUX_CAP_PWM     (0x01 << MUX_PWM)
#define TINY_MUX_CAP_ADC     (0x01 << MUX_ADC)

#define TINY_GPIO_OUT    0x01
#define TINY_GPIO_IN     0x00

#define TINY_GPIO_H      0x01
#define TINY_GPIO_L      0x00


/* ------ for driving system ------ */
#define DRIVE       0x01
#define STOP        0x00
#define DRIVE_FWD   0x02
#define DRIVE_BCK   0x00

#define DRIVE_R     (DRIVE << 0)
#define STOP_R      (STOP  << 0)
#define DRIVE_L     (DRIVE << 4)
#define STOP_L      (STOP  << 4)

#define DRIVE_R_FWD (DRIVE_FWD << 0)
#define DRIVE_R_BCK (DRIVE_BCK << 0)
#define DRIVE_L_FWD (DRIVE_FWD << 4)
#define DRIVE_L_BCK (DRIVE_BCK << 4)

void tinySystemDriver_SetCmd(BYTE cmd);


// for task
LIST_ITEM tinySystemItm;
BOOL init_tinySystem_tsk(void);

// for drawing
BOOL tinySystem_draw(AksImage *img, AksPoint pos);

#endif/*_TINY_SYSTEM_*/
